package team.southcat.wsyygh.order.controllor;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import team.southcat.wsyygh.common.result.Result;
import team.southcat.wsyygh.model.pojo.order.Order;
import team.southcat.wsyygh.model.pojo.order.OrderCountQueryVo;
import team.southcat.wsyygh.model.pojo.order.OrderVo;
import team.southcat.wsyygh.model.pojo.user.PatientVo;
import team.southcat.wsyygh.order.service.OrderService;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author QiuSiYi
 * @since 2023-04-20
 */
@Api(tags = "预约列表管理接口")
@RestController
@RequestMapping("/admin/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @ApiOperation("分页查询订单列表")
    @GetMapping("/getOrderPageList/{page}/{limit}")
    public Result getOrderPageList(@PathVariable int page, @PathVariable int limit, OrderVo orderVo){
        //map包括order total
        Page pageResult = orderService.getOrderPageList(page,limit,orderVo);
        return Result.ok(pageResult);
    }

    @ApiOperation("根据id删除订单信息")
    @DeleteMapping("/deleteOrderById/{id}")
    public Result deleteOrderById(@PathVariable int id){
        boolean flag = orderService.removeById(id);
        return flag ? Result.ok() : Result.fail().message("删除失败");
    }

    @ApiOperation("批量删除订单信息")
    @DeleteMapping("/batchDeleteOrderByIds")
    public Result batchDeleteOrderByIds(@RequestBody List<Integer> ids){
        boolean flag = orderService.removeByIds(ids);
        return flag ? Result.ok() : Result.fail().message("删除失败");
    }

    @GetMapping("/getOrderById/{id}")
    public Result getOrderById(@PathVariable("id") int id){
        OrderVo orderVo = orderService.selectById(id);
        return Result.ok(orderVo);
    }

    @GetMapping("/getPatientById/{id}")
    public Result getPatientById(@PathVariable("id") int id){
        OrderVo orderVo = orderService.selectById(id);
        Long patientId = orderVo.getPatientId();
        PatientVo patientVo = orderService.selectPatientById(patientId);
        return Result.ok(patientVo);
    }

    @ApiOperation("获取订单统计数据")
    @PostMapping ("/inner/getCountMap")
    public Map<String,Object> getCountMap(@RequestBody OrderCountQueryVo orderCountQueryVo){
        System.out.println(orderCountQueryVo);
        return orderService.getCountMap(orderCountQueryVo);
    }

}

